import { apiOrderExpress, apiGetOrderGoodsExpressMessage } from '../../api/index'
import { formatTime } from '../../common/js/timer'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isTrue: false,
    steps: [],
    change: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.optionId = options.id
    this.getOrderExpress()
  },
  getOrderExpress () {
    apiOrderExpress({ orderId: this.optionId }).then(
      res => {
        this.setInfo(res.data.goods_packet_list)
      }
    )
  },
  setInfo (res, idx) {
    const INDEX = idx || 0
    let data = res[INDEX]
    for (let i = 0; i < data.order_goods_list.length; i++) {
      data.order_goods_list[i].express_info.timer = formatTime(data.order_goods_list[i].express_info.shipping_time, 'Y-M-D h:m:s')
    }
    this.setData({
      logisInfo: res,
      goodINfo: res[INDEX],
      change: res[INDEX].express_id
    })
    this.getLogInfo(res[INDEX].express_id)
  },
  getLogInfo (id) {
    apiGetOrderGoodsExpressMessage({ express_id: id }).then(
      res => {
        this.setData({
          steps: res.data.Traces,
          arrLength: res.data.Traces.length - 1
        })
      }
    )
  },
  changeLog (e) {
    this.setInfo(this.data.logisInfo, e.currentTarget.dataset.index)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () {

  }
})
